package data

import (
	"errors"
	"github.com/astaxie/beego/orm"
	_ "github.com/go-sql-driver/mysql"
)

type ImageRepo struct{}

func (i ImageRepo) AddPhoto(id int, photoUrl string, imageType, seq int) (err error) {
	o := orm.NewOrm()
	sql := getPhotoUpdSql(imageType, seq)
	if sql != "" {
		_, err = o.Raw(sql, photoUrl, id).Exec()
	} else {
		err = errors.New("type not exists")
	}

	// var mbr MemberRepo
	// mbr.UpdateAuthState(id, imageType)

	return err
}

func getPhotoUpdSql(imageType, seq int) string {
	if imageType == 0 {
		return SQL_Mbr_Upd_PhotoUrl
	}
	if imageType == 1 {
		if seq == 1 {
			return SQL_Mbr_Upd_Member_ID_Card_FS
		} else {
			return SQL_Mbr_Upd_Member_ID_Card_RS
		}

	} else if imageType == 2 {
		if seq == 1 {
			return SQL_Mbr_Upd_Carrier_Owner_Vehicle_PhotoUrl
		} else if seq == 2 {
			return SQL_Mbr_Upd_Carrier_Owner_Driving_License
		} else if seq == 3 {
			return SQL_Mbr_Upd_Carrier_Owner_Vehicle_License_1
		} else {
			return SQL_Mbr_Upd_Carrier_Owner_Vehicle_License_2
		}
	} else if imageType == 3 {
		return SQL_Mbr_Upd_Cargo_Owner_Biz_License
	} else if imageType == 4 {
		if seq == 1 {
			return SQL_Mbr_Upd_Emp_Biz_License
		} else {
			return SQL_Mbr_Upd_Emp_Biz_Permit
		}
	} else {
		return ""
	}
}
